
import java.util.Arrays;
import java.util.Random;


public class Test {

    //有序，从小到大
    public static void orderArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }

    //无序，从大到小
    public static void notOrderArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array.length-i;
        }
    }

    //乱序
    public static void notOrderArrayRandom(int[] array) {
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10000);
        }
    }

    public static void testQuickSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序耗时："+ (endTime-startTime));
    }

    public static void main(String[] args) {
        int[] array = new int[10000];
        orderArray(array);
        System.out.println("顺序的：");
        testInsertSort(array);
        testShellSort(array);
        testSelectSort(array);
        testHeapSort(array);
        testbubbleSort(array);
        testQuickSort(array);
        testMergeSort(array);
        int[] array2 = new int[10000];
        notOrderArray(array2);//逆序的
        System.out.println("逆序的：");
        testInsertSort(array2);
        testShellSort(array2);
        testSelectSort(array2);
        testHeapSort(array2);
        testbubbleSort(array2);
        testQuickSort(array2);
        testMergeSort(array2);
        int[] array3 = new int[10000];
        notOrderArrayRandom(array3);//乱序的
        System.out.println("乱序的：");
        testInsertSort(array3);
        testShellSort(array3);
        testSelectSort(array3);
        testHeapSort(array3);
        testbubbleSort(array3);
        testQuickSort(array3);
        testMergeSort(array3);
    }
    public static void testMergeSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort. mergeSortNor(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序耗时："+ (endTime-startTime));
    }

    public static void testHeapSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序耗时："+ (endTime-startTime));
    }
    public static void testInsertSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);

        long startTime = System.currentTimeMillis();
        Sort.insertSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("插入排序耗时："+ (endTime-startTime));
    }
    public static void testbubbleSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.bubbleSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("冒泡排序耗时："+ (endTime-startTime));
    }
    public static void testShellSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);

        long startTime = System.currentTimeMillis();
        Sort.shellSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序耗时："+ (endTime-startTime));
    }

    public static void testSelectSort(int[] array) {
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序耗时："+ (endTime-startTime));
    }






    public static void main1(String[] args) {
        int[] array = {1,21,32,4,5,8,10,9,8};
        Sort.quickSort(array);
        System.out.println(Arrays.toString(array));
    }

}